Array.prototype.indexOf = function(val) {
	for ( var i = 0; i < this.length; i++) {
		if (this[i] == val)
			return i;
	}
	return -1;
};
Array.prototype.remove = function(val) {
	var index = this.indexOf(val);
	if (index > -1) {
		this.splice(index, 1);
	}
};
String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

var selectedId = new Array();
var isRightCheck = false;

var winWidth = 0;
var numNum = 0;

$(function() {
	winWidth = $(window).width();
	numNum = parseInt(winWidth / 1600 * 10);
	$(".subbus").each(function() {
		var str = $.trim($(this).html());
		$(this).html(sub(str, numNum));
	});
	$(".subbus").bind('DOMNodeInserted', function() {
		var str = $.trim($(this).html());
		$(this).html(sub(str, numNum));
	});
	// 初始化国家下拉框信息
	$("#guojiaCombo>option").remove();
	$('#guojiaCombo').html("<option value='-1'>请选择</option>");
	var guojiaList = eval($('#guojia').val());
	for ( var i = 0; i < guojiaList.length; i++) {
		$(
				"<option value=" + guojiaList[i].siteid + ">"
						+ guojiaList[i].sitename + "</option>").appendTo(
				$('#guojiaCombo'));
	}
	// 默认已选择
	var selectedSiteList = eval($('#selectedSiteList').val());
	if (selectedSiteList != undefined && selectedSiteList != null
			&& selectedSiteList != "") {
		for ( var j = 0; j < selectedSiteList.length; j++) {
			var siteId = selectedSiteList[j];
			if (siteId.type == 100 || siteId.type == 200) {
				cshCheck(siteId, "jtSelectedDiv");
			} else if (siteId.type == 300) {
				cshCheck(siteId, "gcSelectedDiv");
			} else if (siteId.type == 400) {
				cshCheck(siteId, "qySelectedDiv");
			} else if (siteId.type == 500) {
				cshCheck(siteId, "lcSelectedDiv");
			} else if (siteId.type == 600) {
				cshCheck(siteId, "dpSelectedDiv");
			}
		}
	}
	var pageType = $('#pageType').val();
	// 如果是星期分析和天气分析，不带集团&地区
	if (pageType == "0") {
		$('#jttop').hide();
		$('#jtcenter').hide();
		$('#jtfoot').hide();
		$('#jtkongbai0').hide();
		$('#jtkongbai').hide();
		$('#jtkongbaier').hide();
		$(".chooseSiteMain").css("width","96.5%");
	}
	// 如果是客群分析，不带集团&地区、区域、楼层
	else if (pageType == "1") {
		$('#jttop').hide();
		$('#jtcenter').hide();
		$('#jtfoot').hide();
		$('#jtkongbai0').hide();
		$('#jtkongbai').hide();
		$('#jtkongbaier').hide();
		//$(".chooseSiteMain").css("width","96.5%");
		$('#qyTopDiv').hide();
		$('#lcTopDiv').hide();
		$('#qyDownDiv').hide();
		$('#lcDownDiv').hide();
//		$('#recentPlace').hide();
	}
	// 如果是会员分析，不带区域、楼层、店铺
	else if (pageType == "2") {
		$('#qyTopDiv').hide();
		$('#lcTopDiv').hide();
		$('#qyDownDiv').hide();
		$('#lcDownDiv').hide();
		$('#dpTopDiv').hide();
		$('#dpDownDiv').hide();
		$('#recentPlace').hide();
	}
	var id = $('#gcResultDiv')[0].children[0].children[0].children[0].id;
	// showLoading();
	rightGcCheck(id);
});

// 初始化选中场所
function cshCheck(site, divId) {
	var id = site.siteid;
	var name = site.sitename;
	selectedId.push(id);
	$('#' + id).children().removeClass("hide");
	// 加入广场已选择
	var content = "<div id='selectedDiv"
			+ id
			+ "' class='em45'><div class='em35'><div onclick='deleteCheck(&quot;"
			+ id
			+ "&quot;)' id='selected"
			+ id
			+ "' class='floatleft divcheck'><div class='divchecked'></div></div><span class='floatleft kongxi'></span><div class='em35 lineh35 floatleft paddingL1em' style='width: 60%''>"
			+ name + " </div></div></div>"
	$('#' + divId).append(content);
}

// 搜索集团&地区
function searchJt() {
	var jt = $('#jt_jtSiteName').val().trim();
	$
			.ajax( {
				type : "GET",
				contentType : "application/json",
				data : {
					jt : encodeURI(jt)
				},
				dataType : 'json',
				url : "ajaxSearchJt",
				async : true,
				success : function(msgs) {
					// 获取结果
				var pageResult = msgs.jtList;
				$('#jtResultDiv').empty();
				if (pageResult.length == 0) {
					$('#jtResultDiv').append("没有您要查询的数据！");
				} else {
					for ( var i = 0; i < pageResult.length; i++) {
						var content = "<div class='em45'><div class='em35'><div onclick='leftCheck(&quot;"
								+ pageResult[i].siteid
								+ "&quot;,&quot;jtSelectedDiv&quot;)' id='"
								+ pageResult[i].siteid
								+ "' class='floatleft divcheck'><div class='divchecked hide'></div></div><span class='floatleft kongxi'></span><div title='"
								+ pageResult[i].sitename
								+ "' class='em35 lineh35 floatleft paddingL1em sitecheck subbus' style='width: 60%'>"
								+ sub(pageResult[i].sitename, numNum)
								+ "</div></div></div>";
						$('#jtResultDiv').append(content);
					}
					for ( var i = 0; i < selectedId.length; i++) {
						// 修改样式使选中
						$('#' + selectedId[i]).children().removeClass("hide");
					}
				}
				hideLoading();
			},
			error : function(mm, a, b, c, d, e) {
				hideLoading();
				alert("服务器好像开小差了，刷新一下试试吧！");
			}
			});
}

// 点击地区选择广场
function diquClick(id) {
	$('#gc_dqSiteId').attr("value", id);
	ajaxSearchGc(1);
}

// 广场-选择区划
function comboChange(id) {
	isRightCheck = false;
	var guojia = $('#guojiaCombo').val();
	var sheng = $('#shengCombo').val();
	var shi = $('#shiCombo').val();
	var qu = $('#quCombo').val();
	var changeId = "-1";
	// 如果选择了国家
	if (id == 0) {
		$("#shengCombo>option").remove();
		$("#shiCombo>option").remove();
		$("#quCombo>option").remove();
		$('#shengCombo').html("<option value='-1'>请选择</option>");
		$('#shiCombo').html("<option value='-1'>请选择</option>");
		$('#quCombo').html("<option value='-1'>请选择</option>");
		changeId = guojia;
		$('#gc_countryId').attr("value", guojia);
		$('#gc_provinceId').attr("value", "");
		$('#gc_cityId').attr("value", "");
		$('#gc_areaId').attr("value", "");
	}
	// 如果选择了省
	else if (id == 1) {
		$("#shiCombo>option").remove();
		$("#quCombo>option").remove();
		$('#shiCombo').html("<option value='-1'>请选择</option>");
		$('#quCombo').html("<option value='-1'>请选择</option>");
		changeId = sheng;
		$('#gc_provinceId').attr("value", sheng);
		$('#gc_cityId').attr("value", "");
		$('#gc_areaId').attr("value", "");
	}
	// 如果选择了市
	else if (id == 2) {
		$("#quCombo>option").remove();
		$('#quCombo').html("<option value='-1'>请选择</option>");
		changeId = shi;
		$('#gc_cityId').attr("value", shi);
		$('#gc_areaId').attr("value", "");
	}
	// 如果选择了区
	else if (id == 3) {
		changeId = qu;
		$('#gc_areaId').attr("value", qu);
	}
	// 初始化广场并框中
	else if (id == 4) {
		isRightCheck = true;
		$("#shengCombo>option").remove();
		$("#shiCombo>option").remove();
		$("#quCombo>option").remove();
		$('#shengCombo').html("<option value='-1'>请选择</option>");
		$('#shiCombo').html("<option value='-1'>请选择</option>");
		$('#quCombo').html("<option value='-1'>请选择</option>");
		changeId = guojia;
		$('#gc_countryId').attr("value", guojia);
		$('#gc_provinceId').attr("value", "");
		$('#gc_cityId').attr("value", "");
		$('#gc_areaId').attr("value", "");
	}
	// 下拉框联动
	$.ajax( {
		type : "GET",
		contentType : "application/json",
		data : {
			type : id,
			id : changeId
		},
		dataType : 'json',
		url : "searchCombo",
		async : true,
		success : function(msgs) {
			var siteList = msgs.siteList;
			if (siteList != null && siteList.length > 0) {
				if (id == 0) {
					for ( var i = 0; i < siteList.length; i++) {
						$(
								"<option value=" + siteList[i].siteid + ">"
										+ siteList[i].sitename + "</option>")
								.appendTo($('#shengCombo'));
					}
				} else if (id == 1) {
					for ( var i = 0; i < siteList.length; i++) {
						$(
								"<option value=" + siteList[i].siteid + ">"
										+ siteList[i].sitename + "</option>")
								.appendTo($('#shiCombo'));
					}
				} else if (id == 2) {
					for ( var i = 0; i < siteList.length; i++) {
						$(
								"<option value=" + siteList[i].siteid + ">"
										+ siteList[i].sitename + "</option>")
								.appendTo($('#quCombo'));
					}
				}
			}
			hideLoading();
		},
		error : function(mm, a, b, c, d, e) {
			hideLoading();
			alert("服务器好像开小差了，刷新一下试试吧！");
		}
	});
	ajaxSearchGc(3);
}

// 搜索栏查询广场
function searchGc() {
	// 广场名称
	var gc = $('#gc_gcSiteName').val().trim();
	if (gc == "" || gc == null) {
		$('#gc_gcInput').attr("value", "");
	} else {
		$('#gc_gcInput').attr("value", gc);
	}
	ajaxSearchGc(0);
}

/**
 * ajax请求查询广场数据
 * 
 * @param id
 * @return
 */
function ajaxSearchGc(id) {
	// 关闭当前位置
	closePlace("0");
	// 清空区域、楼层、店铺
	clearRight();
	// 地区
	var diqu = $('#gc_dqSiteId').val();
	// 国家
	var guojia = $('#gc_countryId').val();
	// 省
	var sheng = $('#gc_provinceId').val();
	// 市
	var shi = $('#gc_cityId').val();
	// 区
	var qu = $('#gc_areaId').val();
	// 商圈
	var shangquan = $('#gc_sqSiteId').val();
	// 搜索栏中广场名称
	var guangchang = $('#gc_gcInput').val();
	if (guangchang != undefined && guangchang != "" && guangchang != null) {
		guangchang = guangchang.trim();
	}
	// 如果是点击搜索栏查询广场
	if (id == 0) {
		// diqu = "";
		// guojia = "";
		// sheng = "";
		// shi = "";
		// qu = "";
		// shangquan = "";
	}
	// 如果是选中条件查询广场
	else if (id == 1 || id == 2 || id == 3) {
		// 清空搜索栏
		$('#gc_gcSiteName').attr("value", "");
		// $('#imgx').hide();
		guangchang = "";
	}
	$
			.ajax( {
				type : "GET",
				contentType : "application/json",
				data : {
					diqu : diqu,
					guojia : guojia,
					sheng : sheng,
					shi : shi,
					qu : qu,
					shangquan : shangquan,
					guangchang : encodeURI(guangchang)
				},
				dataType : 'json',
				url : "searchGcSiteSingle",
				async : true,
				success : function(msgs) {
					// 获取结果
				var pageResult = msgs.gcList;
				$('#gcResultDiv').empty();
				if (pageResult.length == 0) {
					$('#gcResultDiv').append("没有您要查询的数据！");
				} else {
					for ( var i = 0; i < pageResult.length; i++) {
						// var content = "<div class='em45'><div
				// class='em35'><div onclick='leftCheck(&quot;"
				// + pageResult[i].siteid
				// + "&quot;,&quot;gcSelectedDiv&quot;)' id='"
				// + pageResult[i].siteid
				// + "' class='floatleft divcheck'><div class='divchecked
				// hide'></div></div><span class='floatleft kongxi'></span><div
				// onclick='showLoading();rightGcCheck(&quot;"
				// + pageResult[i].siteid
				// + "&quot;)' id='right"
				// + pageResult[i].siteid
				// + "' title='"
				// + pageResult[i].sitename
				// + "' class='em35 lineh35 floatleft paddingL1em sitecheck
				// subbus' style='width: 60%'>"
				// + sub(pageResult[i].sitename, numNum)
				// + "</div></div></div>";
				// $('#gcResultDiv').append(content);
				if (pageResult[i].sitestaus == 1) {
					var content = "<div class='em45'><div class='em35'><div onclick='leftCheck(&quot;"
							+ pageResult[i].siteid
							+ "&quot;,&quot;gcSelectedDiv&quot;)' id='"
							+ pageResult[i].siteid
							+ "' class='floatleft divcheck'><div class='divchecked hide'></div></div><span class='floatleft kongxi'></span><div onclick='showLoading();rightGcCheck(&quot;"
							+ pageResult[i].siteid
							+ "&quot;)' id='right"
							+ pageResult[i].siteid
							+ "' title='"
							+ pageResult[i].sitename
							+ "' class='em35 lineh35 floatleft paddingL1em sitecheck subbus' style='width: 60%'>"
							+ sub(pageResult[i].sitename, numNum)
							+ "</div></div></div>";
					$('#gcResultDiv').append(content);
				} else {
					var content = "<div class='em45'><div class='em35'><div id='"
							+ pageResult[i].siteid
							+ "' class='floatleft' style='width:2.1875em;height:2.1875em'></div><span class='floatleft kongxi'></span><div onclick='showLoading();rightGcCheck(&quot;"
							+ pageResult[i].siteid
							+ "&quot;)' id='right"
							+ pageResult[i].siteid
							+ "' title='"
							+ pageResult[i].sitename
							+ "' class='em35 lineh35 floatleft paddingL1em sitecheck subbus' style='width: 60%'>"
							+ sub(pageResult[i].sitename, numNum)
							+ "</div></div></div>";
					$('#gcResultDiv').append(content);
				}
			}
			for ( var i = 0; i < selectedId.length; i++) {
				// 修改样式使选中
				$('#' + selectedId[i]).children().removeClass("hide");
			}
			// 如果需要初始化广场
			if (isRightCheck) {
				// 默认框中第一个广场
				var id = $('#gcResultDiv')[0].children[0].children[0].children[0].id;
				// showLoading();
				rightGcCheck(id);
			}
		}
		hideLoading();
	},
	error : function(mm, a, b, c, d, e) {
		hideLoading();
		alert("服务器好像开小差了，刷新一下试试吧！");
	}
			});
}

// 清空
function qingkong() {
	if (confirm("您是否要清空已选择？")) {
		clearYxz();
		clearGcSX();
	}
	// myConfirm("提示", "您是否要清空已选择？", clearYxz);
}

// 初始化广场筛选
function clearGcSX() {
	// $("#shengCombo>option").remove();
	// $("#shiCombo>option").remove();
	// $("#quCombo>option").remove();
	// $('#shengCombo').html("<option value='-1'>请选择</option>");
	// $('#shiCombo').html("<option value='-1'>请选择</option>");
	// $('#quCombo').html("<option value='-1'>请选择</option>");
	$("#diqu a").removeClass("clickDiqu");
	$('#dq_buxian').addClass("clickDiqu");
	diquClick("-1");
	$('#guojiaCombo').val("-1");
	comboChange(4);
}

// 清空已选择
function clearYxz() {
	// 清空左侧已选择
	for ( var i = 0; i < selectedId.length; i++) {
		$('#' + selectedId[i]).children().addClass("hide");
	}
	// 清空已选择数组
	selectedId.length = 0;
	// 清空已选择div
	$('#jtSelectedDiv').empty();
	$('#gcSelectedDiv').empty();
	$('#qySelectedDiv').empty();
	$('#lcSelectedDiv').empty();
	$('#dpSelectedDiv').empty();
}

// 确定按钮
function queding() {
	var siteString = "";
	for ( var i = 0; i < selectedId.length; i++) {
		// 修改样式使选中
		siteString += selectedId[i] + ",";
	}
	if (siteString == "") {
		alert("请至少选择一个场所！");
		return;
	}
	closeChange('site');
	siteString = siteString.substring(0, siteString.length - 1);
	$('#backGcSiteString').attr("value", siteString);
	$('#backForm').submit();
}

// 选中场所
function leftCheck(id, divId) {
	// 获取选择类型-单选、多选
	var selectType = $('#selectType').val();
	// 如果是选中事件
	if ($('#' + id).children().hasClass("hide")) {
		if (selectedId.length > 6) {
			alert("最多选择7个场所！");
			return;
		}
		// 如果是单选
		if (selectType == 0) {
			clearYxz();
		}
		selectedId.push(id);
		$('#' + id).children().removeClass("hide");
		// 加入广场已选择
		var name = $('#' + id).next().next()[0].childNodes[0].data;
		var titleName = $('#' + id).next().next()[0].title;
		var content = "<div title='"
				+ titleName
				+ "' id='selectedDiv"
				+ id
				+ "' class='em45'><div class='em35'><div onclick='deleteCheck(&quot;"
				+ id
				+ "&quot;)' id='selected"
				+ id
				+ "' class='floatleft divcheck'><div class='divchecked'></div></div><span class='floatleft kongxi'></span><div class='em35 lineh35 floatleft paddingL1em' style='width: 60%''>"
				+ name + " </div></div></div>"
		$('#' + divId).append(content);
	}
	// 如果是取消选中事件
	else {
		deleteCheck(id);
	}
}

// 广场右侧点击
function rightGcCheck(id) {
	$('#hxPlace').remove();
	$('#otherPlace').remove();
	$('#secondSiteId').attr("value", "");
	$('#gcPlace').remove();
	// var secondSiteId = $('#secondSiteId').val();
	// // 如果当前位置有两个场所
	// if (secondSiteId != null && secondSiteId != "") {
	// $('hxPlace').remove();
	// $('otherPlace').remove();
	// }
	var yixuanzeId = $('#firstSiteId').val();
	if (yixuanzeId != "") {
		$('#right' + yixuanzeId).removeClass("sitechecked");
	}
	$('#firstSiteId').attr("value", id);
	var name = $('#' + id).next().next()[0].childNodes[0].data;
	var titleName = $('#' + id).next().next()[0].title;
	// 加入当前位置
	var content = "<div title='"
			+ titleName
			+ "' id='gcPlace' class='floatleft lineh35 weizhiKuang'><span class='paddingL10'>"
			+ name
			+ "</span><img onclick='closePlace(&quot;0&quot;)' src='images/xx2.png' class='closeX' /></div>";
	$('#recentPlace').append(content);
	$('#right' + id).addClass("sitechecked");
	ajaxQyLcDp("0", id);
}

// 区域、楼层、店铺右侧点击
function rightOtherCheck(id, type) {
	// 如果是重复点击
	if ($('#right' + id).hasClass("sitechecked")) {
		return;
	} else {
		var secondSiteId = $('#secondSiteId').val();
		// 如果是第一次点击
		if (secondSiteId != null && secondSiteId != "") {
			// myAlert("提示", "亲，不能再点啦~");
			// alert("亲，不能再点啦~");
			hideLoading();
			return;
		}
		ajaxQyLcDp(type, id);
	}
}

// 关闭当前位置
function closePlace(type) {
	// 如果是点击关闭了广场
	if (type == 0) {
		$('#hxPlace').remove();
		$('#otherPlace').remove();
		$('#gcPlace').remove();
		var gcSiteId = $('#firstSiteId').val();
		$('#right' + gcSiteId).removeClass("sitechecked");
		$('#firstSiteId').attr("value", "");
		clearRight();
	}
	// 如果是点击关闭了区域、楼层、店铺
	else if (type == 1) {
		$('#hxPlace').remove();
		$('#otherPlace').remove();
		$('secondSiteId').attr("value", "");
		var gcSiteId = $('#firstSiteId').val();
		rightGcCheck(gcSiteId);
	}
}

// 清空区域、楼层、店铺内容
function clearRight() {
	$('#qyResultDiv').empty();
	$('#lcResultDiv').empty();
	$('#dpResultDiv').empty();
}

// 取消选中
function deleteCheck(id) {
	// 删除已选中数组中的id
	for ( var i = 0; i < selectedId.length; i++) {
		if (selectedId[i] == id) {
			selectedId.remove(selectedId[i]);
			break;
		}
	}
	$('#' + id).children().addClass("hide");
	$('#selectedDiv' + id).remove();
}

// 点击按钮查询区域
function searchQy() {
	var gcSiteId = $('#firstSiteId').val();
	// 如果没有当前位置，则不响应查询
	if (gcSiteId == null || gcSiteId == "") {
		hideLoading();
		return;
	}
	var secondSiteId = $('#secondSiteId').val();
	var id = "";
	if (secondSiteId != null && secondSiteId != "") {
		id = secondSiteId;
	} else {
		id = gcSiteId;
	}
	var siteName = $('#qy_qySiteName').val().trim();
	if (siteName != null && siteName != "") {
		siteName = "qy_" + siteName;
	}
	ajaxQyLcDp(4, id, siteName);
}

// 点击按钮查询楼层
function searchLc() {
	var gcSiteId = $('#firstSiteId').val();
	// 如果没有当前位置，则不响应查询
	if (gcSiteId == null || gcSiteId == "") {
		hideLoading();
		return;
	}
	var secondSiteId = $('#secondSiteId').val();
	var id = "";
	if (secondSiteId != null && secondSiteId != "") {
		id = secondSiteId;
	} else {
		id = gcSiteId;
	}
	var siteName = $('#lc_lcSiteName').val().trim();
	if (siteName != null && siteName != "") {
		siteName = "lc_" + siteName;
	}
	ajaxQyLcDp(4, id, siteName);
}

// 点击按钮查询店铺
function searchDp() {
	var gcSiteId = $('#firstSiteId').val();
	// 如果没有当前位置，则不响应查询
	if (gcSiteId == null || gcSiteId == "") {
		hideLoading();
		return;
	}
	var secondSiteId = $('#secondSiteId').val();
	var id = "";
	if (secondSiteId != null && secondSiteId != "") {
		id = secondSiteId;
	} else {
		id = gcSiteId;
	}
	var siteName = $('#dp_dpSiteName').val().trim();
	if (siteName != null && siteName != "") {
		siteName = "dp_" + siteName;
	}
	ajaxQyLcDp(4, id, siteName);
}

// ajax查询区域、楼层、店铺信息
function ajaxQyLcDp(type, id, siteName) {
	var gc = "";
	var qy = "";
	var qyName = "";
	var lc = "";
	var lcName = "";
	var dp = "";
	var dpName = "";
	var siteId = "";
	if (siteName != undefined && siteName != null && siteName != "") {
		var leixing = siteName.substring(0, 2);
		var site = siteName.substring(3);
		if (leixing == "qy") {
			qyName = site;
		} else if (leixing == "lc") {
			lcName = site;
		} else if (leixing == "dp") {
			dpName = site;
		}
	}
	if (type == 0) {
		gc = id;
	} else if (type == 1) {
		qy = id;
	} else if (type == 2) {
		lc = id;
	} else if (type == 3) {
		dp = id;
	} else if (type == 4) {
		siteId = id;
	}
	$
			.ajax( {
				type : "GET",
				contentType : "application/json",
				data : {
					gc : gc,
					qy : qy,
					lc : lc,
					dp : dp,
					qyName : encodeURI(qyName),
					lcName : encodeURI(lcName),
					dpName : encodeURI(dpName),
					siteId : siteId
				},
				dataType : 'json',
				url : "ajaxSearchQyLcDp",
				async : true,
				success : function(msgs) {
					// 获取结果
				var qyResult = msgs.qyList;
				var lcResult = msgs.lcList;
				var dpResult = msgs.dpList;
				if (qyResult.length == 0 && lcResult.length == 0
						&& dpResult.length == 0) {
					$('#qyResultDiv').empty();
					$('#lcResultDiv').empty();
					$('#dpResultDiv').empty();
					$('#qyResultDiv').append("没有您要查询的数据！");
					$('#lcResultDiv').append("没有您要查询的数据！");
					$('#dpResultDiv').append("没有您要查询的数据！");
					hideLoading();
					// alert("亲，没有其他场所了哦~");
					return;
				}
				if (type != 0 && type != 4) {
					$('#secondSiteId').attr("value", id);
					var name = $('#' + id).next().next()[0].childNodes[0].data;
					var titleName = $('#' + id).next().next()[0].title;
					var content = "<div title='"
							+ titleName
							+ "' id='otherPlace' class='floatleft lineh35 weizhiKuang'><span class='paddingL10'>"
							+ name
							+ "</span><img onclick='closePlace(&quot;1&quot;)' src='images/xx2.png' class='closeX' /></div>";
					var duanxian = "<div id='hxPlace' class='floatleft lineh35'><span>&nbsp;-&nbsp;</span></div>";
					$('#recentPlace').append(duanxian);
					$('#recentPlace').append(content);
				}
				// // 如果不是点击广场加入当前位置
				// if (type != 0) {
				// var name = $('#' + id).next().next()[0].childNodes[0].data;
				// var content = "<div id='otherPlace' class='floatleft lineh35
				// weizhiKuang'><span class='paddingL10'>"
				// + name
				// + "</span><img onclick='closePlace(&quot;1&quot;)'
				// src='images/xx2.png' class='closeX' /></div>";
				// var duanxian = "<div id='hxPlace' class='floatleft
				// lineh35'><span>&nbsp;-&nbsp;</span></div>";
				// $('#recentPlace').append(duanxian);
				// $('#recentPlace').append(content);
				// }
				$('#qyResultDiv').empty();
				$('#lcResultDiv').empty();
				$('#dpResultDiv').empty();
				if (qyResult.length == 0) {
					$('#qyResultDiv').append("没有您要查询的数据！");
				} else {
					for ( var i = 0; i < qyResult.length; i++) {
						var content = "<div class='em45'><div class='em35'><div onclick='leftCheck(&quot;"
								+ qyResult[i].siteid
								+ "&quot;,&quot;qySelectedDiv&quot;)' id='"
								+ qyResult[i].siteid
								+ "' class='floatleft divcheck'><div class='divchecked hide'></div></div><span class='floatleft kongxi'></span><div onclick='showLoading();rightOtherCheck(&quot;"
								+ qyResult[i].siteid
								+ "&quot;,&quot;1&quot;)' id='right"
								+ qyResult[i].siteid
								+ "' title='"
								+ qyResult[i].sitename
								+ "' class='em35 lineh35 floatleft paddingL1em sitecheck subbus' style='width: 60%'>"
								+ sub(qyResult[i].sitename, numNum)
								+ "</div></div></div>";
						$('#qyResultDiv').append(content);
					}
				}
				if (lcResult.length == 0) {
					$('#lcResultDiv').append("没有您要查询的数据！");
				} else {
					for ( var i = 0; i < lcResult.length; i++) {
						var content = "<div class='em45'><div class='em35'><div onclick='leftCheck(&quot;"
								+ lcResult[i].siteid
								+ "&quot;,&quot;lcSelectedDiv&quot;)' id='"
								+ lcResult[i].siteid
								+ "' class='floatleft divcheck'><div class='divchecked hide'></div></div><span class='floatleft kongxi'></span><div onclick='showLoading();rightOtherCheck(&quot;"
								+ lcResult[i].siteid
								+ "&quot;,&quot;2&quot;)' id='right"
								+ lcResult[i].siteid
								+ "' title='"
								+ lcResult[i].sitename
								+ "' class='em35 lineh35 floatleft paddingL1em sitecheck subbus' style='width: 60%'>"
								+ sub(lcResult[i].sitename, numNum)
								+ "</div></div></div>";
						$('#lcResultDiv').append(content);
					}
				}
				if (dpResult.length == 0) {
					$('#dpResultDiv').append("没有您要查询的数据！");
				} else {
					for ( var i = 0; i < dpResult.length; i++) {
						var content = "<div class='em45'><div class='em35'><div onclick='leftCheck(&quot;"
								+ dpResult[i].siteid
								+ "&quot;,&quot;dpSelectedDiv&quot;)' id='"
								+ dpResult[i].siteid
								+ "' class='floatleft divcheck'><div class='divchecked hide'></div></div><span class='floatleft kongxi'></span><div onclick='showLoading();rightOtherCheck(&quot;"
								+ dpResult[i].siteid
								+ "&quot;,&quot;3&quot;)' id='right"
								+ dpResult[i].siteid
								+ "' title='"
								+ dpResult[i].sitename
								+ "' class='em35 lineh35 floatleft paddingL1em sitecheck subbus' style='width: 60%'>"
								+ sub(dpResult[i].sitename, numNum)
								+ "</div></div></div>";
						$('#dpResultDiv').append(content);
					}
				}
				for ( var i = 0; i < selectedId.length; i++) {
					// 修改样式使选中
					$('#' + selectedId[i]).children().removeClass("hide");
				}
				hideLoading();
			},
			error : function(mm, a, b, c, d, e) {
				hideLoading();
				alert("服务器好像开小差了，刷新一下试试吧！");
			}
			});
}
$(function() {
	$("#jtSelectedDiv").bind('DOMNodeInserted', function(e) {
		changeHeight(1, 0);
	});
	$("#gcSelectedDiv").bind('DOMNodeInserted', function(e) {
		changeHeight(2, 0);
	});
	$("#qySelectedDiv").bind('DOMNodeInserted', function(e) {
		changeHeight(3, 0);
	});
	$("#lcSelectedDiv").bind('DOMNodeInserted', function(e) {
		changeHeight(4, 0);
	});
	$("#dpSelectedDiv").bind('DOMNodeInserted', function(e) {
		changeHeight(5, 0);
	});
	$("#jtSelectedDiv").bind('DOMNodeRemoved', function(e) {
		changeHeight(1, 1);
	});
	$("#gcSelectedDiv").bind('DOMNodeRemoved', function(e) {
		changeHeight(2, 1);
	});
	$("#qySelectedDiv").bind('DOMNodeRemoved', function(e) {
		changeHeight(3, 1);
	});
	$("#lcSelectedDiv").bind('DOMNodeRemoved', function(e) {
		changeHeight(4, 1);
	});
	$("#dpSelectedDiv").bind('DOMNodeRemoved', function(e) {
		changeHeight(5, 1);
	});
})
function changeHeight(site, type) {
	var maxh = 1;// 最大子集数
	var maxhc = 1;// 当前字集数
	maxh = $("#jtSelectedDiv").children('div').length;
	maxhc = $("#gcSelectedDiv").children('div').length;
	if (site == 2 && maxhc > 1 && type == 1) {
		maxhc = maxhc - 1;
	}
	if (maxh <= maxhc) {
		maxh = maxhc;
	}
	maxhc = $("#qySelectedDiv").children('div').length;
	if (site == 3 && maxhc > 1 && type == 1) {
		maxhc = maxhc - 1;
	}
	if (maxh <= maxhc) {
		maxh = maxhc;
	}
	maxhc = $("#lcSelectedDiv").children('div').length;
	if (site == 4 && maxhc > 1 && type == 1) {
		maxhc = maxhc - 1;
	}
	if (maxh <= maxhc) {
		maxh = maxhc;
	}
	maxhc = $("#dpSelectedDiv").children('div').length;
	if (site == 5 && maxhc > 1 && type == 1) {
		maxhc = maxhc - 1;
	}
	if (maxh <= maxhc) {
		maxh = maxhc;
	}
	maxh = maxh * 2.8125;
	$("#jtSelectedDiv").css("height", maxh + "em");
	$("#gcSelectedDiv").css("height", maxh + "em");
	$("#qySelectedDiv").css("height", maxh + "em");
	$("#lcSelectedDiv").css("height", maxh + "em");
	$("#dpSelectedDiv").css("height", maxh + "em");
}